﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ContractManagementSystem.DataAccessLayer;

namespace ContractManagementSystem.BusinessLogicLayer
{
    public static class AuthorizationChecker
    {
        // Url is a string
        public static void IsValidAuthorization(string userName, int functionId, HttpResponse httpResponse, string urlToCome)
        { 
            var validUser = AuthorizationDao.CheckAuthorization(userName, functionId);
           
            if (!validUser)
            {
                httpResponse.Redirect(urlToCome);
            }
        }

        // Url is an Uri
        public static void IsValidAuthorization(string userName, int functionId, HttpResponse httpResponse, Uri urlToCome)
        {
            var validUser = AuthorizationDao.CheckAuthorization(userName, functionId);

            if (!validUser)
            {
                httpResponse.Redirect(urlToCome.AbsoluteUri);
            }
        }

    }
}
